<script>
$(document).ready(function(){
  $("#subscription-table tr td:first-child").css( "color", "#eb6841" );
});
</script>

<div class="row">
  <div class="col-md-8 col-md-offset-2">

    {{#is_sub_active defaultSub}}
    <div class="alert alert-danger">
      <p>
	Testing updates are activated. These are cutting edge updates that should
	be applied only after careful consideration. When an update is released,
	read the changelog and proceed with caution.
      </p>
      <p>
	Alternatively, Stable updates are generally recommended as shown below.
      </p>
    </div>
    {{/is_sub_active}}

    {{#no_sub_active}}
    <div class="alert alert-success">
      <p>
	You can receive software updates from one of the two update channels as
	shown in the below table. Please activate a channel that is appropriate
	for your needs. Stable updates are generally recommended, unless you want
	to actively test Rockstor. If you have questions, email
	support@rockstor.com
      </p>
    </div>
    {{/no_sub_active}}

    {{#is_sub_active stableSub}}
    {{else}}
    <table class="table table-hover" id="subscription-table">
      <thead>
	<tr class="active">
          <th>Feature</th>
          <th>Stable Updates</th>
          <th>Testing Updates</th>
	</tr>
      </thead>
      <tbody>
	<tr>
          <td>Update Frequency</td>
          <td>3-4 Weeks</td>
          <td>2-3 days</td>
	</tr>
	<tr>
          <td>Priority of bug fixes</td>
          <td>Highest</td>
          <td>Varies</td>
	</tr>
	<tr>
          <td>Automated functional testing</td>
          <td><i class="fa fa-check"></i></td>
          <td><i class="fa fa-check"></i></td>
	</tr>
	<tr>
          <td>Tested in development environment</td>
          <td><i class="fa fa-check"></i></td>
          <td><i class="fa fa-check"></i></td>
	</tr>
	<tr>
          <td>Low risk of regressions</td>
          <td><i class="fa fa-check"></i></td>
          <td><i class="fa fa-times"></i></td>
	</tr>
	<tr>
          <td>Tested in production environment</td>
          <td><i class="fa fa-check"></i></td>
          <td><i class="fa fa-times"></i></td>
	</tr>
	<tr>
          <td>Tested by community</td>
          <td><i class="fa fa-check"></i></td>
          <td><i class="fa fa-times"></i></td>
	</tr>
	<tr>
          <td></td>
          <td><a id="stable-modal" class="btn btn-success" title="Activate Stable subscription">Activate</a></td>
	  {{#is_sub_active defaultSub}}
          <td><a id="testing-modal" class="btn btn-danger" title="Activate Testing subscription" disabled>Currently Active</a></td>
	  {{else}}
          <td><a id="testing-modal" class="btn btn-danger" title="Activate Testing subscription">Activate</a></td>
	  {{/is_sub_active}}
	</tr>
      </tbody>
    </table>
    {{/is_sub_active}}
  </div><!-- col-md-8 -->
</div><!-- row-->


{{#update_available}}
<br>
<div class="col-sm-offset-3 col-sm-6 col-sm-offset-3">
  <div id="updateInfo">
    <h3><strong>Rockstor {{mostRecentVersion}}</strong> update is available! </h3>
  </div>
</div>&nbsp;&nbsp;&nbsp;&nbsp;
<br><br>
<div class="col-sm-offset-2 col-sm-8 col-sm-offset-2">
  <div id="changeSection">
    <p>List of changes in this update</p>
    <ul>
      {{#each changeMap}}
      <li><p>{{this}}</p></li>
      {{/each}}
    </ul>
    {{#is_sub_active defaultSub}}
    <p>
      You should review the
      changelog <a href="https://github.com/rockstor/rockstor-core/commits/master"
		   target="_blank">here</a> before proceeding with the update.
    </p>
    {{/is_sub_active}}
  </div>
</div>

<div class="col-md-offset-2 col-md-8 col-md-offset-2" id="supportBox">
  {{#is_sub_active defaultSub}}
  <div class="alert alert-success" id="contrib-alert">
    <h4>We are happy to make this update available to you. Please support us by
      <a id="donateYes" href="#version"> Donating</a> or making a <a href="http://shop.rockstor.com" target="_blank"> Purchase</a></h4>
  </div>
  {{/is_sub_active}}
  <a id="update" class="btn btn-primary" title="start update">Start Update</a>
</div>

{{else}}
<div class="col-md-offset-3 col-md-6 col-md-offset-3">
  <div id="updateInfo">
    <h3>System is running the latest Rockstor version: {{currentVersion}}</h3>
    <p>If you've updated recently, reload the browser<b>(Ctrl+Shift+R)</b> for latest UI changes.</p><br>

    {{#if autoUpdateEnabled}}
    <a id="autoUpdateSwitch" class="btn btn-primary" title="Rockstor is configured to check for available system updates and automatically upgrade all packages on a daily basis. This will keep your entire system up to date. While it's not recommended, you can disable this feature and only update when you want to.">Disable auto update</a>
    {{else}}
    <a id="autoUpdateSwitch" class="btn btn-primary" title="Rockstor can be configured to check for available system updates and automatically upgrade all packages on a daily basis. We recommend you enable this feature to keep your entire system up to date without delay.">Enable auto update</a>
    {{/if}}
  </div>
</div>
{{/update_available}}

<div class="col-md-offset-3 col-md-6 col-md-offset-3">
  {{#is_sub_active stableSub}}
  <div id="updateInfo" class="alert alert-success">
    <p></p>
    <p>
      Stable updates are activated. While it's not recommended, if you are
      absolutely sure, Testing updates can be activated by clicking <a id="testing-modal"> here.</a>
    </p>
  </div>
  {{/is_sub_active}}
</div>

<div id="update-modal" class="modal fade" role="dialog" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
	<h4>Rockstor is being updated to the latest version. Please wait... &nbsp;&nbsp; </h4>
      </div>
      <div class="modal-body">
	<div style="text-align: center">
	  <img src="/static/storageadmin/img/ajax-loader-big.gif">
	  <div id="time-left"></div>
	</div>
	<div id="user-msg" style="display: none">The Rockstor update is still going on. if the page does not automatically refresh after a few minutes, please try manually refreshing after some time.</div>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

<form id="contrib-form" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank"i style="display:none">
  <input type="hidden" name="cmd" value="_xclick" />
  <input type="hidden" name="business" value="WUDA5UNJXDCZ8" />
  <input type="hidden" name="currency_code" value="USD" />
  <input type="hidden" name="item_name" value="Support Rockstor development" />
  <input type="hidden" name="amount" value="10" />
  <input type="hidden" name="cn" value="Note to Rockstor developers" />
  <input type="hidden" name="no_shipping" value="1" />
</form>

<div id="activate-stable" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h3 class="modal-title">Activate Stable updates.</h3>
      </div>
      <div style="font-size: 13px" class="modal-body">
	<p>
	  Please follow these steps to activate Stable updates.
	</p>
	<ol>
	  <li>Purchase the Activation code by clicking <a href="http://shop.rockstor.com/products/stable-release-channel-subscription#applianceid={{applianceId}}" target="_blank">here.</a>
	  <li>The Activation code will be sent to you via e-mail.</li>
	  <li>Come back to this screen and enter the Activation code.</li>
	  <li>Enjoy Stable updates. Thanks for supporting Rockstor!</li>
	</ol>
	<form id="activate-stable-form" name="aform" class="form-horizontal">
	  <div class="form-group">
	    <label class="col-sm-4 control-label" for="activation-code">Activation Code <span class="required">*</span></label>
	    <div class="col-sm-4">
	      {{#if stableSub}}
	      <input class="form-control" type="text" id="activation-code" value="{{stableSub.password}}"name="activation-code">
	      {{else}}
	      <input class="form-control" type="text" id="activation-code" name="activation-code">
	      {{/if}}
	    </div>
	  </div>
	  <p style="color:'#eb6841'">UUID for reference: {{applianceId}}</p>
	  <div class="modal-footer">
  	    <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>
  	    <a id="activateStable" class="btn btn-primary" title="Activate">Activate</a>
	  </div>
	</form>
      </div>
    </div>
  </div>
</div>
</div>

<div id="activate-testing" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Activate Testing updates</h4>
      </div>
      <div class="modal-body">
	<p>
	  Testing updates are high frequency updates that are released just
	  after testing in development environment as opposed to Stable updates
	  that are released only after significant testing and qualification
	  process. Because of this, Testing updates are cutting edge that are
	  generally not recommended.
	</p>
	<p>
	  Whenever an update is released, read the changelog and decide to
	  update or not after careful consideration.
	</p>
      	<p>Are you sure?</p>
      </div>
      <div class="modal-footer">
      <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>
      <a id="activateTesting" class="btn btn-primary" title="Activate">Activate</a>
      </div>
    </div>
  </div>
</div>

<div id="auto-update-modal" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
	{{#if autoUpdateEnabled}}
        <h4 class="modal-title">Disable auto updates</h4>
	{{else}}
	<h4 class="modal-title">Enable auto updates</h4>
	{{/if}}
      </div>
      <div class="modal-body">
	{{#if autoUpdateEnabled}}
	<p>
	  Currently Rockstor is configured to check for available system updates
	  and automatically upgrade all packages on a daily basis. This will keep
	  your entire system up to date. Disabling auto updates is only
	  recommended when you have Testing updates activated.
	</p>
	{{else}}
	{{#is_sub_active defaultSub}}
	<div class="alert alert-danger">
	  <p>
	    Testing updates are activated on this system. Enabling auto updates
	    is strongly discouraged while this is the case.
	  </p>
	</div>
	{{/is_sub_active}}
	<p>
	  By enabling auto updates, Rockstor will check for available system
	  updates and automatically upgrade all packages on a daily
	  basis. Enabling this feature is recommended except when Testing
	  updates are active.
	</p>
	{{/if}}
      	<p>Are you sure?</p>
	<div class="modal-footer">
	  <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>
	  {{#if autoUpdateEnabled}}
	  <a id="disableAuto" class="btn btn-primary" title="Activate">Disable auto updates</a>
	  {{else}}
	  <a id="enableAuto" class="btn btn-primary" title="Activate">Enable auto updates</a>
	  {{/if}}
	</div>
      </div>
    </div>
  </div>
</div>
